﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Antioch.Base.PlayerStates
{
    internal class Jump : IState
    {
        public void Enter(StateMachine Machine)
        {
            Machine.DrawComponent.Play("Rise", true);
            Machine.PhysicsComponent.PhysicsBody.GetFixtureList().SetFriction(0.0f);
            Machine.PhysicsComponent.PhysicsBody.ApplyLinearImpulse(
                    -( Jemgine.Math.Vector.Normalize(Machine.PhysicsComponent.Gravity) ) * Machine.Settings.JumpForce,
                    Machine.PhysicsComponent.PhysicsBody.Position);
            Vector2 StickDir = new Vector2(Machine.Input.NavigationStick.X, 0);
            StickDir = Vector2.Transform(StickDir, Matrix.CreateRotationZ(Machine.PlayerEntity.Angle));
            Machine.PhysicsComponent.PhysicsBody.ApplyLinearImpulse(StickDir * Machine.Settings.RunForce,
                Machine.PhysicsComponent.PhysicsBody.Position);
        }

        public void Leave(StateMachine Machine)
        {
            
        }

        public void Update(StateMachine Machine)
        {
            //Vector2 Velocity = Machine.PhysicsComponent.PhysicsBody.GetLinearVelocity();
            //Velocity = Vector2.Transform(Velocity, Matrix.CreateRotationZ(-Machine.PlayerEntity.Angle));

            //if (Machine.PhysicsComponent.IsOnGround || Velocity.Y < 0)
                Machine.Transition(typeof(Fall));
        }
    }
}
